﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdDgnImport : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDgnImport(IntPtr cPtr, bool cMemoryOwn) : base(GlobalsPINVOKE.OdDgnImport_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDgnImport obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDgnImport()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdDgnImport(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public virtual OdDgnImport.ImportResult import()
		{
			OdDgnImport.ImportResult result = (OdDgnImport.ImportResult)GlobalsPINVOKE.OdDgnImport_import(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdRxDictionary properties()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdDgnImport_properties(this.swigCPtr);
			OdRxDictionary result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdRxDictionary)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		public enum ImportResult
		{
			success,
			fail,
			bad_password,
			bad_file,
			bad_database,
			encrypted_file
		}
	}
}
